<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>遍历对象内的数组</title>
</head>

<body>
  <script>
    var selected = {
      hotelLevel: [1, 2],
      hotelType: [3, 4]
    };
    var str = "";
    // [hotelLevel, hotelType]
    Object.keys(selected).forEach(key => {
      // 如果是数组，循环对象的属性
      if (Array.isArray(selected[key])) {
        // [1,2]
        selected[key].forEach(v => {
          str += (key + "_in=") + v + "&";
        });
      }
    });
    console.log(str);


    // Object.keys(selected).forEach(key =>{
    //   console.log(key);  //hotelLevel，hotelType
    // })
  </script>
</body>

</html>